/**
 * 
 */
package com.etong.citymap.connect;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import com.etong.citymap.util.StringUtil;
import com.etong.citymap.util.log.LogUtil;
import com.supermap.data.Point2D;

/**
 * @author skyline
 *
 */
public class NetOperation {

	//flag=0   坐标转换  1轨迹添加
	public static void getNetGps(Point2D point, boolean isNet,int flag,String userId, String userCode,String httpUrl){
		
		String url = "supervisor/ashx/TrackAdd.ashx"; // 001 001
		Map<String, String> map = new HashMap<String, String>();
		map.put("inLon",point.getX()+"");
		map.put("inLat", point.getY()+"");
		map.put("flag", flag+"");
		map.put("superid", userId);
		map.put("code", userCode);

		try{
			String result = HttpSendData.SendGet(url, map, "utf-8",httpUrl);
			//System.out.println(result); 
			//MessageBox.Show(flag+"_______"+result);
		}catch(Exception e){
			LogUtil.e(e);
		}
	}
	
	//flag=0   坐标转换  1轨迹添加
			public static Point2D getNetGps(double lo, double la, double h, boolean isNet,int flag,String userId, String userCode,String httpUrl){
				Point2D p_null = new Point2D(0, 0);
				
				if (!isNet) return p_null;
				lo = lo / 360000;
				la = la / 360000;
				//lo = (((lo % 360000) % 6000 / 3600) + (lo % 360000) / 6000) / 60 + lo / 360000;
				//la = (((la % 360000) % 6000 / 3600) + (la % 360000) / 6000) / 60 + la / 360000;
				if (la == 0 || lo == 0) return p_null;

				String url = "supervisor/ashx/TrackAdd.ashx"; // 001 001
				Map<String, String> map = new HashMap<String, String>();
				map.put("inLon",StringUtil.format(lo, 6, 2));
				map.put("inLat", StringUtil.format(la, 6, 2));
				map.put("inH", h+"");
				map.put("flag", flag+"");
				map.put("superid", userId);
				map.put("code", userCode);

				try{
					String result = HttpSendData.SendGet(url, map, "utf-8",httpUrl);
					//MessageBox.Show(flag+"_______"+result);
					if (result == null ||result == "-1" )
					{
						//MessageBox.Show("服务器发生错误！请联系管理员，或稍微再试！");
						return p_null;
					}
					else if (result.equals("-3"))
					{
						return p_null;
					}
					else if (result.equals("-4"))
					{
						//MessageBox.Show("您的帐户已在其他地方登录，如果继续操作，请重新登录。");
						return p_null;
					}
					else
					{
						JSONObject json = new JSONObject(result);
						//Hashtable CdoorMap = (Hashtable)JSONObject(result);
						int taskCount = Integer.parseInt(json.get("newtask").toString());
						if ((int)Double.parseDouble(json.get("xcoor").toString()) == 0) return p_null;
						else
							return new Point2D((int)(Double.parseDouble(json.get("xcoor").toString()) * 10), (int)(Double.parseDouble(json.get("ycoor").toString()) * 10));

					}
				}catch(Exception e){
					LogUtil.e(e);
					return p_null;
				}
			}
}
